﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using DataAccessLayer;

namespace DALUnitTesting
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class DataAccessLayerTest
    {

        DBNegotiator Negotiator = new DBNegotiator();
        public DataAccessLayerTest()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        [TestMethod]
        public void AddStation_withSattion_Success()
        {
            Station station = new Station();
            station.Name = "Israel channel 10";
            station.URL = "http://switch206-01.castup.net/cunet/gm.asp?ai=506&amp;ar=LiveBkp";
            Negotiator.AddStation(station);
        }

        [TestMethod]
        public void GetStations_returnStationList()
        {
            var stationList = Negotiator.GetStations();
            Assert.AreSame(typeof(List<Station>), stationList.GetType());
        }

        [TestMethod]
        public void GetStationByID_WithStationID_returnStation()
        {
            var result = Negotiator.GetStationByID(1);
            Assert.AreSame(typeof(Station),result.GetType());
        }

        [TestMethod]
        public void GetStationByID_WithWrongStationID_returnNull()
        {
            var result = Negotiator.GetStationByID(2);
            Assert.AreSame(null, result);
        }

        [TestMethod]
        public void RegisterUser_withUser_ReturneID()
        {
            User user = new User();
            user.UserName = "yuval";
            user.Password = "123456";
            var id = Negotiator.RegisterUser(user);
            Assert.AreEqual(1, id);
        }

        [TestMethod]
        public void GetUserStations_withUserID_returnUserSettings()
        {
            var result = Negotiator.GetUserStations(1);
            Assert.AreSame(typeof(UserSetting), result.GetType());
        }

        [TestMethod]
        public void SaveUserStations_withUserSettings_Success()
        {
            List<UserSetting> settings = new List<UserSetting>();
            settings.Add(new UserSetting() { UserID = 1, TVStation = 1 }); ;
            Negotiator.SaveUserStations(settings);
        }

        [TestMethod]
        public void GetUserID_WithUserNameAndPassword_returnID()
        {
            var res = Negotiator.GetUserID("yuval", "123456");
            Assert.AreEqual(1, res);
        }
    }
}
